package com.yue.gmall.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yue.common.utils.PageUtils;
import com.yue.common.utils.Query;
import com.yue.gmall.product.dao.AttrGroupDao;
import com.yue.gmall.product.entity.AttrGroupEntity;
import com.yue.gmall.product.service.AttrGroupService;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("attrGroupService")
public class AttrGroupServiceImpl extends ServiceImpl<AttrGroupDao, AttrGroupEntity> implements AttrGroupService {

    @Override
    public PageUtils queryPage(Map<String, Object> params, Long categoryId) {
        LambdaQueryWrapper<AttrGroupEntity> lambda = new QueryWrapper<AttrGroupEntity>().lambda();
        IPage<AttrGroupEntity> page = this.page(
                new Query<AttrGroupEntity>().getPage(params),
                0 == categoryId ? lambda : lambda
                        .and(
                                entity -> entity.eq(AttrGroupEntity::getCatelogId, categoryId)
                                        .or()
                                        .likeRight(AttrGroupEntity::getAttrGroupName, categoryId)));


        return new PageUtils(page);
    }

}